package com.example.webchar.webchar.controller;

import com.example.webchar.webchar.service.ChapteService;
import com.example.webchar.webchar.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: webchars
 * @description
 * @author: 毛叶贵子
 * @create: 2021-08-28 08:30
 **/
@CrossOrigin
@RestController
@RequestMapping("/chapter")
public class ChapteController {
    @Autowired
    private ChapteService chapteService;

    /**
     * 根据小说id返回章节信息
     *
     * @param novelId 小说id
     * @return
     */
    @GetMapping("/query/{novelId}")
    public Result quereyChapter(@PathVariable Integer novelId) {
        return novelId.equals(null) ? Result.fail().add("err", "请选择小说id") : Result.success().add("success", chapteService.queryChapte(novelId));
    }

    /**
     * 根据小说id删除小说
     *
     * @param novelId
     * @return
     */
    @GetMapping("/delete/{novelId}")
    public Result deleteNovel(@PathVariable Integer novelId) {
        return novelId.equals(null) ? Result.fail().add("err", "请选择小说id") : chapteService.deleteNovel(novelId) ? Result.success().add("success", "删除成功") : Result.fail().add("err", "删除失败");
    }
}
